#version 150

#moj_import <light.glsl>
#moj_import <fog.glsl>

in vec3 Position;
in vec4 Color;
in vec2 UV0;
in ivec2 UV2;
in vec3 Normal;

uniform sampler2D Sampler2;

uniform mat4 ModelViewMat;
uniform mat4 ProjMat;
uniform vec3 ChunkOffset;
uniform int FogShape;
uniform float GameTime;

out float vertexDistance;
out vec4 vertexColor;
out vec2 texCoord0;
out vec3 normal;

bool check_float(float textureAlpha, float targetAlpha) {//用于检测10进制alpha值的函数
	
	float targetLess = targetAlpha - 0.001;
	float targetMore = targetAlpha + 0.001;
	return (textureAlpha > targetLess && textureAlpha < targetMore);
	
}

void main() {
    vec3 pos = Position + ChunkOffset;
    float strength = 1.0;
    if(check_float(fract(Position.y),1.145/16.0)){
        pos.y += strength * sqrt(0.25 - pow((fract(Position.x) - 0.5), 2.0) - pow ((fract(Position.z) - 0.5), 2.0));    
    }else if(check_float(fract(Position.y),1.045/16.0)){
        pos.y -= strength * (sqrt(0.25 - pow((fract(Position.x) - 0.5), 2.0) - pow ((fract(Position.z) - 0.5), 2.0)) - 0.1);    
    }
    gl_Position = ProjMat * ModelViewMat * vec4(pos, 1.0);

    vertexDistance = fog_distance(ModelViewMat, pos, FogShape);
    vertexColor = Color * minecraft_sample_lightmap(Sampler2, UV2);

    texCoord0 = UV0;
    normal = vec3(fract(Position.x) - 0.5, fract(Position.z) - 0.5, z)/r;
}
